// pages/my/walletpasswordset/walletpasswordset.js
Page({
  data: {
    tel: "",
    code: "",
    password: "",
    surePassword: "",
    toggle: true,
    timer: null,
    second: 60 * 1000,
  },
  onLoad: function (options) {
    this.setData({
      tel: wx.getStorageSync("userInfo").mobile,
      timer: this.selectComponent(".timer")
    });
  },
  getCode() {
    getApp().globalData.http.sendMsg().then(res => {
      getApp().globalData.vant.toast(res.msg);
      this.setData({
        toggle: false
      });
      this.data.timer.reset();
      this.data.timer.start();
    }).catch(e => {
      getApp().globalData.vant.toast(e.msg);
    });
  },
  finished() {
    this.setData({
      toggle: true
    });
  },
  submit() {
    let params = {
      code: this.data.code,
      password: this.data.password,
      surePassword: this.data.surePassword,
    }
    if (!params.password) {
      getApp().globalData.vant.toast("请输入验证码");
    } else if (!/^\d{6}$/.test(params.password) || !/^\d{6}$/.test(params.surePassword)) {
      getApp().globalData.vant.toast("提现密码为6位数字");
    } else if (params.password != params.surePassword) {
      getApp().globalData.vant.toast("密码和确认密码不一致");
    } else {
      getApp().globalData.http.setPayPwd(params).then(res => {
        getApp().globalData.vant.toast({
          type: "success",
          message: res.msg,
          onClose: () => {
            wx.navigateBack();
          }
        });
      }).catch(e => {
        getApp().globalData.vant.toast(e.msg);
      });
    }
  }
})